package main

import "fmt"

func main() {
	var a1 A = Cat{"白色"}
	var a2 A = Per{"隔壁老王"}
	var a3 A = "哈哈哈哈"
	var a4 A = 100
	fmt.Println(a1)
	fmt.Println(a2)
	fmt.Println(a3)
	fmt.Println(a4)

	//map key字符串，value任意类型
	map1 := make(map[string]interface{})
	map1["name"] = "王二狗"
	map1["age"] = 30
	map1["friend"] = Per{"李小花"}
	fmt.Println(map1)

	//切片，存储任意类型
	slice1 := make([]interface{}, 0, 10)
	slice1 = append(slice1, a1, a2, a3, a4, "sss", map1)
	fmt.Println(slice1)
	test(slice1)

	/*	testSlice := []int{11,22,33,44}
		// 成功拷贝
		var newSlice []int
		newSlice = testSlice
		fmt.Println(newSlice)
		// 拷贝失败
		var any []interface{}
		any = testSlice
		fmt.Println(any)*/
}

func test(slice2 []interface{}) {
	for i := 0; i < len(slice2); i++ {
		fmt.Printf("第%d个元素是：%v \n", i+1, slice2[i])
	}
}

//定义空接口
type A interface{}

type Cat struct {
	color string
}
type Per struct {
	name string
}
